    #include <stdio.h>  
    #include <string.h>  
    #include <stdlib.h>  
    #include <unistd.h>  
    #include <sys/socket.h>  
    #include <sys/un.h>  
      
    #define SERVER "server_sock"   
      
    int main(int argc ,char *argv[])  
    {  
        int sockfd = 0;  
        struct sockaddr_un addr, recvaddr;  
        
        unlink(SERVER);    
        addr.sun_family = AF_LOCAL;  
        strcpy(addr.sun_path,SERVER);  
      
        socklen_t len = sizeof(addr);
        socklen_t recvlen = sizeof(recvaddr);
        sockfd = socket(AF_LOCAL,SOCK_DGRAM,0);  
        if(sockfd < 0 )  
        {  
            perror("socket error");  
            exit(-1);  
        }  
      
        if(bind(sockfd,(struct sockaddr *)&addr,len) < 0)  
        {  
            perror("bind error");  
            close(sockfd);  
            exit(-1);  
        }  
        printf("Bind is ok\n");  
        fd_set fdR;
        struct timeval timeout, tmp;
        timeout.tv_sec = 3;
        timeout.tv_usec = 0;
        tmp = timeout;
      
        while(1)  
        {  
            FD_ZERO(&fdR);
            FD_SET(sockfd, &fdR);
            switch (select(sockfd + 1, &fdR, NULL, NULL , &tmp)) 
            {
                case -1:
                    printf("error\n");
                    break;
                case 0:
                    printf("timeout\n");
                    tmp = timeout;
                    break;
                default:
                    if (FD_ISSET(sockfd, &fdR)) {
                        char recv_buf[20] = "";  
                        recvfrom(sockfd,recv_buf,50,0,(struct sockaddr*)&recvaddr,&recvlen);   
                        int byte = sendto(sockfd,recv_buf,strlen(recv_buf),0,(struct sockaddr*)&recvaddr,sizeof(recvaddr));
                        printf("byte %d\n", byte);
                    }
            }
        }  
        return 0;  
      
    } 